const express = require('express')
const {SuccessModel, ErroModel} = require('../models/common')
const UserModel = require('../models/Users')

let User = express.Router()


User.get('/:id', (req, res) => {
    let user = UserModel.findById(req.params.id,function(err, usern) {
        if(err) {
            res.json(new ErroModel(err))
            return
        }
        res.json(new SuccessModel(usern)) 
    })
})

User.post('/', (req, res) => {
    console.log(req.body.userName)
    let user = UserModel(req.body)
    user.save(function(err) {
        if(err) {
            res.json(new ErroModel(err, "Error:"))
        }
    })
    res.json(new SuccessModel(this, "user Created!"))
})

User.get('/', (req, res) => {

})

module.exports = User